from flask import Flask,jsonify,request
from config import Config
from db import db1
import json
app = Flask(__name__)
#加载配置文件
app.config.from_object(Config)
#跨域配置
from flask_cors import CORS
CORS(app)
@app.route('/test')
def test():
    sql1 = "insert into test values(0,'页面基本定期')"
    db1.update(sql1)
    sql = "select * from test"
    res = db1.find_all(sql)
    return jsonify({'list':res})
    # return res


@app.route('/add',methods=["POST"])
def add():
    gain = request.data
    if gain:
        gain=json.loads(gain)
    else:
        gain = request.form
    sql1 = "insert into test(name) values('%s')"%(gain['name'])
    db1.update(sql1)
    sql = "select * from test"
    res = db1.find_all(sql)
    return jsonify({'list':res})
    # return res

if __name__=="__main__":
    app.run(debug=True)